package com.duoketech.controller.weixin;

import com.duoketech.controller.BaseController;
import com.duoketech.exception.ValidateException;
import com.duoketech.model.party.Party;
import com.duoketech.utils.validator.Validator;
import com.duoketech.utils.validator.rules.string.StringLengthBetween;
import com.duoketech.utils.validator.rules.string.StringMustBeRequired;
import com.jfinal.aop.Clear;

@Clear
public class PartyController extends BaseController{

	public void index() {
		
		String sql="select * from "+Party.dao.tableName()+" order by id desc ";
		setAttr("applyList",Party.dao.find(sql));
		setAttr("titleTemp", "电气923同学10年聚会登记表");
		setAttr("subTitle", "岁月如歌，爱如少年");
		render("index.html");
	}
	public void apply() {
		setAttr("titleTemp", "电气923同学10年聚会登记表");
		setAttr("subTitle", "岁月如歌，爱如少年");
		render("apply.html");
	}
	
	
	public void doSave() {
        try {
        	Party party = getModel(Party.class,"");
    		Validator validator = new Validator();
    		String name = party.getStr("name");
    		String size = party.getStr("size");
    		String mobile = party.getStr("mobile");
    		String address = party.getStr("address");
    		String company = party.getStr("company");
    		
            validator.addRule(new StringMustBeRequired(name,"请输入姓名"));
            validator.addRule(new StringLengthBetween(name,"姓名只能是1-10个字以内",1,10));
            
            validator.addRule(new StringMustBeRequired(mobile,"请输入手机号码"));
            validator.addRule(new StringLengthBetween(mobile,"手机号码最长不能超过11位",1,11));
            
            validator.addRule(new StringMustBeRequired(company,"请输入工作单位"));
            validator.addRule(new StringLengthBetween(company,"工作单位只能是1-50个字符",1,50));
            
            validator.addRule(new StringMustBeRequired(size,"请输入衣服尺码"));
            validator.addRule(new StringMustBeRequired(address,"请输入家庭住址"));
            validator.addRule(new StringLengthBetween(address,"家庭住址只能是1-50个字符",1,50));
			validator.excute();
			party.save();
			renderSuccess("报名成功...");
		} catch (ValidateException e) {
			renderError(e.getMessage());
		}
	}
	
	public void detail() {
		render("detail.html");
	}
}
